// const uni_cloud_admin = 'env-00jxtfooq39v'
const uni_cloud_admin = 'env-00jxtxlp4rei';
const BASE_URL = `https://${uni_cloud_admin}.dev-hz.cloudbasefunction.cn`;

export function request(config = {}) {
	let { url, data = {}, method = 'POST', header = {} } = config;

	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + url,
			data,
			method,
			header,
			success: (res) => {
				if (res.data.errCode === 0) {
					resolve(res.data);
				} else if (res.data.errCode === 400) {
					uni.showModal({
						title: '错误提示',
						content: res.data.errMsg,
						showCancel: false
					});
					reject(res.data);
				} else {
					uni.showToast({
						title: res.data.errMsg,
						icon: 'none'
					});
					reject(res.data);
				}
			},
			fail: (err) => {
				reject(err);
			}
		});
	});
}
